package com.shiro.test;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * description: Shiro 入门
 * @version v1.0
 * @author w
 * @date 2018年10月25日下午2:49:09
 */
public class HelloShiro {
	
	private static final Logger logger = LoggerFactory.getLogger(HelloShiro.class);
	
	public static void main(String[] args) {
		@SuppressWarnings("deprecation")
		Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
		SecurityManager securityManager = factory.getInstance();	
		SecurityUtils.setSecurityManager(securityManager);
		
		
		// 获取当前用户 
		Subject subject = SecurityUtils.getSubject();
		
		subject.isPermitted("dd");
		UsernamePasswordToken token = new UsernamePasswordToken("shiro", "1314");
		token.setRememberMe(true);
		
		try {
			subject.login(token);
		} catch (AuthenticationException e) {
			logger.info(" login failure ..",e );
			return ;
		}
		
		logger.info("login success ... ");
		System.out.println(" 程序 执行 结束啦啦啦啦 。。。 ");
	}
	
	
}
